<%@page import="com.is.export.control.SelectOptionValue"%>
<%@page import="java.util.LinkedHashMap"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="com.is.model.User"%>
<%@page import="com.is.util.Common"%>
<%@page import="com.is.model.CourseClass"%>
<%@page import="com.is.util.DateTime"%>
<%@page import="com.is.control.ParamStuyearControl"%>
<%@page import="com.is.util.ParamUtil"%>
<%@page import="java.util.List"%>
<%@page import="com.is.model.ParamStuyear"%>
<%@page import="com.is.control.CourseClassControl"%>
<%@page import="com.is.control.ParamClassControl"%>
<%@page import="com.is.control.ParamCourseControl"%>
<%@page import="com.is.model.Student"%>
<%@page import="com.is.control.StudentControl"%>
<%@page import="com.is.util.DesData"%>
<%@page import="com.is.control.CourseScoreControl"%>
<%@page import="com.is.model.CourseScore"%>
<%@page import="com.is.model.ParamCourseScoreGS"%>
<%@page import="com.is.control.ParamCourseScoreGSControl"%>
<%@page import="com.is.export.model.ScoreExport"%>
<%@page import="java.util.ArrayList"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="/InterStu/resources/image/favicon.ico" />
<link rel="stylesheet" type="text/css" href="../../resources/css/all.css" />
<link href="../../resources/css/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../../resources/js/jquery-1.8.1.js"></script>
<script type="text/javascript" src="../../resources/js/jquery.artDialog.js"></script>
<script type="text/javascript" src="../../resources/js/WebCalendar.js"></script>
<script type="text/javascript" src="../../resources/js/iframeTools.js"></script>
<script type="text/javascript">
	(function (config) {
	    config['fixed'] = true;
	    config['okVal'] = '确定';
	    config['cancelVal'] = '取消';
		config['skin'] = 'default';
		config['drag'] = 'true';
	    // [more..]
	})(art.dialog.defaults);	
	$(function(){
		$(".update").click(function(){
			$.dialog.open("/InterStu/update_info.jsp",{width:460,height:400,title:"个人信息"});
		})
		$('img').error(function(){
			this.src = "/InterStu/resources/image/man.GIF";
		})
		var block = $("#magic_block");
		if($(".active a").position()){
			block.css("top",$(".active a").position().top+10)
			.data("oriTop",$(".active a").position().top)
		}
		$(".nav ul li").find("a").hover(
			function(){
				var $this = $(this);
				var newTop = $this.position().top;
				block.stop().animate({
					top:newTop+10
				})
			},
			function(){
				block.stop().animate({
					top:block.data("oriTop")+10
				})
			}
		)
		var h = $(".right").height();
		$(".left").height(h);
		$(".team").click(function(){
			$.dialog.open("transform.jsp",{width:460,height:400,title:"折算公式"});
		})
		$(".allCourse").click(function(){
			var url = $(this).attr("rel");
			$.dialog.open(url,{
			title:"查看成绩",
			width:620,
			cancel: true,
			cancelVal: "关闭"
			});
		})
		$("[name='stuyear']").change(function(){
			var selectYear = $(this).val();
			$.ajax({
				type:"post",
				dataType:"html",
				url:"../homework/select_option.jsp",
				data:{
					stuYearId:selectYear
				},
				cache:false,
				success:function(data){
					$("[name='courseClassId']")[0].options.length = 0;
					$("[name='courseClassId']").append(data);
				}
			})
		})
	})
	function doSubmit(){
      var submit = document.getElementById("submit");
      submit.disabled="disabled";
      return true;
	}
	
</script>
<style type="text/css">
	.team{text-shadow:none;}
</style>
<title>留学生预科班</title>
</head>
<body>
<%
     User cu = (User)session.getAttribute("user");
%>
<div class="header">
	<div class="title pr">
    	<a href="javascript:void(0);"><span class="update pa">个人信息</span></a>
        <span class="logout pa"><a class="hide" href="/InterStu/login/logout.jsp">退出</a></span>
    </div>
</div>
<div class="main">
	<div class="left">  
		<div class="infomation">
			<div class="photo">
			<%
			String picUrl = cu.getPicUrl();
			%>
				<img width='60' height="60" src = "<%=picUrl %>"  />
			</div>
			<div class="welcome">
				<%=cu.getName() %>,<br/>
				欢迎您使用！
			</div>
		</div>  	
    	<div class="nav">
        	<ul>	
        		<li class="pa" id="magic_block"></li>
            	<%if(cu!=null&&cu.getRole().equals("1")){ %>
                <li><a href="/InterStu/pages/stuyear/stuyear_start.jsp">新学期设置</a></li>
                <li><a href="/InterStu/pages/users/user_all.jsp">用户管理</a></li>
                <%} %>
                <li><a href="/InterStu/pages/students/student_add.jsp">学生管理</a></li>
                <li class="active"><a href="/InterStu/pages/dictation/dictation_add.jsp">学生考核</a></li>
                <%if(cu!=null&&cu.getRole().equals("1")){ %>
                <li><a href="/InterStu/pages/assess/teacher_assess.jsp">教职人员管理</a></li>
                <%} %>
            </ul>
        </div>
    </div>
    <div class="right">
    	<div class='r1'>
    	<table class="dictations tab">
	    <tr>
	    	<td>
	    		<a href="/InterStu/pages/dictation/dictation_add.jsp">听写成绩</a>
			</td>
			<td>
				<a href="/InterStu/pages/homework/homework_add.jsp">作业成绩</a>			
			</td>
			<td>
				<a class="current" href="/InterStu/pages/courseScore/score_go.jsp">成绩录入</a>
			</td>
			 <%if(cu!=null&&cu.getRole().equals("1")){ %>
			<td>
				<a href="/InterStu/pages/evaluation/students_all.jsp">综合评价</a>
			</td>
			<%} %>
	    </tr>
	    </table>
    	<%
	   //这个页面需要获取
	   List<CourseClass> ccs = null;
	   String time1 = DateTime.SimpleDate();
	   String time2 = DateTime.SimpleDate();
	   int stuyear = ParamStuyearControl.getCurrentStuyearId();
	   int usingStuyear = ParamUtil.getInt(request,"stuyear",stuyear);
	   session.setAttribute("stuYearId",usingStuyear);
	   ParamStuyear usingPS = ParamStuyearControl.getStuyear(usingStuyear);
	   List<ScoreExport> exportList = new ArrayList<ScoreExport>();
	   int courseClassId = ParamUtil.getInt(request,"courseClassId",0);
	   if(usingStuyear!=0&&usingPS!=null){
	         time1 = usingPS.getStartTime();//默认为本学期开学时间
	     }else{
		    time1 = ParamUtil.getString(request,"time1",usingPS.getStartTime());
	     }
	   if(stuyear==usingStuyear){
	        time2 = ParamUtil.getString(request,"time2",DateTime.SimpleDate());
	   }else{
		    time2 = usingPS.getEndTime();
	   }
	   int stuYear = (Integer)session.getAttribute("stuYearId");
	   if(cu!=null&&cu.getRole().equals("1")){
		   //管理员应该能查看所有的课程班级出勤情况
		  ccs = CourseClassControl.getAllCourseClassIdByUidAndStuyear(0,stuYear);
		  ccs = Common.sortCourseClassName(ccs);  //对班级+课程名排序
	   }
	   if(cu!=null&&cu.getRole().equals("0")){
		   //任课教师看到自己所带课程的出勤情况
		   ccs = CourseClassControl.getAllCourseClassIdByUidAndStuyear(cu.getId(),stuYear);
		   ccs = Common.sortCourseClassName(ccs);  //对班级+课程名排序
	   }
	   if(ccs==null||ccs.size()==0){
		   out.print("本学期尚未有任何课程教学工作。");
	   }else{
	   %>
	   <form action="score_statistics.jsp" method="post">
	   <table class='table'>
	   <caption>请选择</caption>
	   <tr>
	   <td width="20%">学期</td>
	   <td width="20%"><select name="stuyear" style="width:90%;" >
	   <%
	    List<ParamStuyear> stuyears = ParamStuyearControl.getAllStuyear();
	     for(ParamStuyear ps:stuyears){
	    	 %>
	    	 <option value="<%=ps.getId() %>"  <%if(ps.getId()==usingStuyear)out.print("selected"); %>><%=ps.getStuyear() %></option>
	    	 <%
	     }
	   %>
	   </select></td>
	   <td width="20%">
	   		班级&课程
	   </td>
	   <td width="20%">
	   		<select name="courseClassId" style="width:90%;">
			   <%
			      for(CourseClass cc:ccs){
			   %>
			   <option value="<%=cc.getId() %>" <%if(cc.getId()==courseClassId)out.print("selected"); %>><%=ParamClassControl.getClassName(cc.getClassId()) %><%=ParamCourseControl.getCourseById(cc.getCourseId()).getCourseName() %></option>
			   <%} %>
		   </select>
	   </td>
       <td width="20%"><input type="submit" value="查询"/></td>
       </tr>
       </table>
	   </form>
	   <%
   }
   
   %>
   </div>
   <div class="r2">
   <%
        if(courseClassId!=0){
        	CourseClass nowcc = CourseClassControl.getCourseClassById(courseClassId);
        	String courseName = ParamCourseControl.getCourseById(nowcc.getCourseId()).getCourseName();
        	String className = ParamClassControl.getClassName(nowcc.getClassId());
        	List<Student> stus = StudentControl.getStudentByClassId(String.valueOf(nowcc.getClassId()));
        	DesData des = new DesData();
        	 ParamCourseScoreGS gs = ParamCourseScoreGSControl.getGSByCourseClassId(courseClassId);
        	%>
        	<form>
        	<table class="table">
        	<caption>
        		<%=className %>【<%=courseName %>】具体成绩如下 【总成绩=出勤(<%=gs.getAttendance_per()+"%" %>)平时(<%=gs.getDailyScore_per()+"%" %>)+期中(<%=gs.getMiderScore_per() +"%"%>)+期末(<%=gs.getFinalScore_per() +"%"%>)】
        	【<a href="/InterStu/servlet/ExportDo" target="_blank">导出查询结果</a>】        	</caption>
        	<thead>
        	<tr>
        	<th>姓名</th>
        	<th>出勤成绩(满分<%=100*Double.parseDouble(gs.getAttendance_per())/100 %>)</th>
			<th>平时成绩(占<%=100*Double.parseDouble(gs.getDailyScore_per())/100 %>%)</th>
			<th>期中成绩(占<%=100*Double.parseDouble(gs.getMiderScore_per())/100 %>%)</th>
			<th>期末成绩(占<%=100*Double.parseDouble(gs.getFinalScore_per())/100 %>%)</th>
        	<th>总成绩(满分100)</th>
        	</tr>
        	</thead>
        	<tbody>
        	<%
        	  for(Student stu:stus){
        	      CourseScore cs = CourseScoreControl.getCSByStuIdAndCourseId(courseClassId,stu.getId());
        	      String attScore = (cs!=null)?cs.getAttendanceScore():"0.0";
        	      String daily = (cs!=null)?cs.getDailyScore():"0.0";
        	      String mid = (cs!=null)?cs.getMidtermScore():"0.0";
        	      String finalS = (cs!=null)?cs.getFinalScore():"0.0";
        		  String total = (cs!=null)?cs.getTotalScore():"0.0";
        		  %>
        		  <tr>
        		  <td><a href="javascript:void(0);" class="allCourse" rel="allCoursesOneStu.jsp?stuId=<%=des.encrypt(String.valueOf(stu.getId())) %>"><%=stu.getChineseName() %></a></td>
        		 <td><%=attScore%></td>
        		 <td><%=daily%></td>
        		 <td><%=mid %></td>
        		 <td><%=finalS %></td>
        		 <td><%=total %></td>
   		   </tr>
   		  <%
   		  ScoreExport se = new ScoreExport();
   		  se.setCourseName(courseName);
   		  se.setDailyScore(daily);
   		  se.setFinalScore(finalS);
   		  se.setMidtermScore(mid);
   		  se.setTotalScore(total);
   		  se.setStuName(stu.getChineseName());
   		  se.setAttScore(attScore);
   		  exportList.add(se);
   		  }
        	session.removeAttribute("exportList");
        	session.setAttribute("exportList",exportList);
        	session.removeAttribute("fileName");
        	session.setAttribute("fileName",className+courseName+"成绩情况");
        	 LinkedHashMap<String,String> exportOps = SelectOptionValue.ScoreOptions();
        	 session.removeAttribute("exportOps");
        	 session.setAttribute("exportOps",exportOps);
        	 session.removeAttribute("className");
        	 session.setAttribute("className","com.is.export.model.ScoreExport");
          %>
        	</tbody>
        	</table>
        	</form>
        	<%
        }
   %>
    </div>
    </div>
</div>
<div class="footer">
	<p>版权所有：东北师范大学留学生预科部&nbsp;&nbsp;  蓝旭工作室开发</p>
</div>
 </body>
</html>